<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="javax.sql.rowset.WebRowSet" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>修改购物车数据</title>

<style>
 body {
    font-family: 'Arial', sans-serif;
    background-color: #f9f9f9; 
    margin: 0;
    padding: 20px;
  }
  
  .container2 {
    max-width: 600px;
    margin: 0 auto; 
    padding: 20px;
    background: #fff; 
    border-radius: 8px; 
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  }

  .form-wrapper2 {
    border: 1px solid #e5e5e5; 
  }

  h1 {
    color: #3f3f3f; 
    text-align: center;
    margin-bottom: 20px;
  }

  label {
    display: block; 
    margin-bottom: 5px;
    color: #666;
  }

  input[type="text"],
  input[type="number"],
  input[type="submit"],
  input[type="hidden"] {
    width: 96.5%;
    padding: 10px;
    margin-bottom: 10px;
    border: 1px solid #ccc; 
    border-radius: 4px;
  }

  input[type="submit"] {
    background-color: #99B898; 
    color: white;
    border: none;
    cursor: pointer;
    transition: background-color 0.3s ease;
  }

  input[type="submit"]:hover {
    background-color: #82a085;
  }

  input[readonly] {
    background-color: #e9f0e9;
  }

  
  .text-center {
    text-align: center;
  }

  .mb-20 {
    margin-bottom: 20px;
  }
</style>
</head>
<body>
<div class="container2">
    <div class="form-wrapper2">
        <form action="ordersave.jsp" method="post">
           
            <%
            request.setCharacterEncoding("utf-8");
            String dish_id = request.getParameter("dish_id");
            if(dish_id != null && !dish_id.isEmpty()) {
         
                dish_id = java.net.URLEncoder.encode(dish_id, "UTF-8");
                String sql = "SELECT * FROM shoppingcar WHERE dish_id='" + dish_id + "'";
                WebRowSet rs = aa.db.DBTools.getRS(sql);

                if (rs != null && rs.next()) {
               
                    String name = rs.getString("name");
                    double price = rs.getDouble("price");
                    int amount = rs.getInt("amount");
                    String table_id = rs.getString("table_id");
                    String restaurant_id = rs.getString("restaurant_id");
                 
                    %>
                    <input type="hidden" id="dish_id" name="dish_id" value="<%=dish_id%>">
                    <label for="name">餐品名称:</label>
                    <input type="text" id="name" name="name" value="<%=name%>" required>
                    <label for="price">单价:</label>
                    <input type="text" id="price" name="price" value="<%=price%>" required readonly>
                    <label for="amount">数量:</label>
                    <input type="number" id="amount" name="amount" value="<%=amount%>" required min="1" max="100">
                    <input type="hidden" id="table_id" name="table_id" value="<%=table_id%>" required>
                    <input type="hidden" id="restaurant_id" name="restaurant_id" value="<%=restaurant_id%>" required>
                    <%
                } else {
              
                    response.sendRedirect("errorPage.jsp?error=dishNotFound");
                    return;
                }
                rs.close();
            } else {
          
                response.sendRedirect("errorPage.jsp?error=noDishId");
                return;
            }
            %>
            <input type="hidden" name="btn" value="修改">
            <input type="submit" value="提交修改">
        </form>
    </div>
</div>
</body>
</html>